package cn.yunhe.controller;

import cn.yunhe.entity.Province;
import cn.yunhe.service.IProvinceService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/after/UpdateProvinceServlet")
public class UpdateProvinceServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Province provinces= (Province) request.getSession().getAttribute("province");
        String government = request.getParameter("government");
        String city = request.getParameter("city");
        Double chinaN = Double.parseDouble(request.getParameter("chinaN"));
        Double chinaE = Double.parseDouble(request.getParameter("chinaE"));
        Province province= new Province(provinces.getId(),government,city,chinaN,chinaE);
        IProvinceService provinceService = new IProvinceService();

        if (provinceService.updateProvince(province)){
            response.sendRedirect("GetAllProvinceServlet");
        }else{
            response.sendRedirect("/after/province-list.jsp");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
